package producerconsumer;

public class Producer implements Runnable {
    private final Buffer buffer;

    public Producer(Buffer buffer) {
        this.buffer = buffer;
    }

    public void run() {
        try {
            int i = 0;
            while (true) {
                buffer.put( Integer.toString(i) );
                i++;
                Thread.sleep((long) (Math.random() * 1000.0));
            }
        } catch (InterruptedException e) {
            // allow thread to die
        }
    }
}
